package com.xuwang.service.impl;

import com.github.pagehelper.PageHelper;
import com.xuwang.mapper.GovernmentInformGMapper;
import com.xuwang.pojo.GovernmentInformG;
import com.xuwang.service.GovernmentInformServiceG;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GovernmentInformServiceGGImpl implements GovernmentInformServiceG {

    @Resource
    private GovernmentInformGMapper governmentInformGMapper;

    @Override
    public Map<String, Object> insertInform(String inform) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 500);
        map.put("msg","新增通知失败");
        GovernmentInformG governmentInformG = new GovernmentInformG();
        governmentInformG.setInform(inform);
        governmentInformG.setInformDay(new Date(System.currentTimeMillis()));
        if(governmentInformGMapper.inserInform(governmentInformG)>0){
            map.put("code", 200);
            map.put("msg","新增通知成功");
            return map;
        }
        return map;
    }

    @Override
    public Map<String, Object> selectAll(String inform, String informDay, int page, int limit) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 500);
        map.put("msg","查找失败");
        PageHelper.startPage(page,limit);
        List<GovernmentInformG> governmentInformGS = governmentInformGMapper.selectAll(inform, informDay);
        if(governmentInformGS !=null){
            map.put("code", 200);
            map.put("AllCount", governmentInformGMapper.selectAll(null, null).size());
            map.put("count", governmentInformGS.size());
            map.put("data", governmentInformGS);
            map.put("msg","查询成功");
            return map;
        }
        return map;
    }
}
